package com.csiec.clock.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;

import com.csiec.clock.R;
import com.csiec.clock.bean.MyClock;
import com.csiec.clock.bean.UserInfo;
import com.csiec.clock.bean.myJoinClock.InformationList;
import com.csiec.clock.bean.myJoinClock.JoinClock;
import com.csiec.clock.databinding.ActivityFaceBinding;
import com.csiec.clock.utils.Base64Util;
import com.csiec.clock.view.model.FaceViewModel;
import com.github.cliven.circlecamerapreview.CircleCameraPreview;
import com.qmuiteam.qmui.widget.QMUIProgressBar;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class FaceActivity extends AppCompatActivity {
    private final String[] NEEDED_PERMISSION = new String[]{Manifest.permission.CAMERA};
    private final String TAG = FaceActivity.class.getSimpleName();

    private static final int REQ_CODE = 0x001;
    private ActivityFaceBinding binding;
    private FaceViewModel faceViewModel;

    private String activityInfo;
    private JoinClock ownClock;


    /**
     * 圆形摄像头预览控件
     */
    private CircleCameraPreview circleCameraPreview;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_face);
        binding.constraintlayout10.setBackgroundResource(R.drawable.bai);

        //LiveData
        faceViewModel = new ViewModelProvider(this).get(FaceViewModel.class);
        binding.setFaceviewModel(faceViewModel);
        binding.setLifecycleOwner(this);

        //接受Intent传来的数据
        Intent intent = getIntent();
        activityInfo = (String) intent.getSerializableExtra("activityInfo");
        ownClock = (JoinClock) intent.getSerializableExtra("join_card");

        if (ContextCompat.checkSelfPermission(this, NEEDED_PERMISSION[0])
                != PackageManager.PERMISSION_GRANTED) {
            // 没有相机权限则停止运行
            ActivityCompat.requestPermissions(this, NEEDED_PERMISSION, REQ_CODE);
            this.finish();
            return;
        }
        faceViewModel.init(this, binding, activityInfo, ownClock);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}